package com.itheima;

import java.util.Objects;

//用 private 对成员变量进行保护。需要编写 getXXX / setXXX 方法，才能对private限定的成员变量进行访问
public class Student_plus {
    private String name;
    private int age;
    public Student_plus(){}   //无参构造方法
    public Student_plus(String name,int age){  //含参构造方法
        this.name = name;
        this.age = age;
    }
    public void setName(String name){
        this.name = name;
    }
    public void setAge(int age){
        if(age < 0 || age > 100)
            System.out.println("Input is error !");
        else
            this.age = age;
    }
    public String getName(){
        return name;
    }
    public int getAge(){
        return age;
    }

    @Override
    public String toString() {    //重写 toString类
        return "Student_plus{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    @Override
    public boolean equals(Object o) {          // 重写 equals类
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Student_plus that = (Student_plus) o;
        return age == that.age && name.equals(that.name);
    }

}
